package com.ljm.spring01.controller;

import com.ljm.spring01.MyDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/book")
public class BookController {

    // 读取yaml数据中的单一数据
    @Value("${country}")
    private String country;

    @Value("${user.name}")
    private String name1;

    // 使用自动装配将所有的数据封装到一个对象Environment中
    @Autowired
    private Environment env;

    @Autowired
    private MyDataSource myDataSource;

    @GetMapping
    public String getById(){
        System.out.println("Springboot is running ....2");
        System.out.println("country===>"+country);
        System.out.println("name===>"+name1);
        System.out.println("-------------------------");
        System.out.println(env.getProperty("server.port"));
        System.out.println(env.getProperty("user.name"));
        System.out.println("-------------------------");
        System.out.println(myDataSource);
        return "Springboot is running ....2"+" "+name1;
    }
}
